=begin
{{> api_info}}
=end

require 'forwardable'

# Common files
require '{{gemName}}/api_client'
require '{{gemName}}/api_error'
require '{{gemName}}/version'
require '{{gemName}}/configuration'

# Models
{{^useAutoload}}
{{#models}}
{{#model}}
{{^parent}}
require '{{gemName}}/{{modelPackage}}/{{classFilename}}'
{{/parent}}
{{/model}}
{{/models}}
{{#models}}
{{#model}}
{{#parent}}
require '{{gemName}}/{{modelPackage}}/{{classFilename}}'
{{/parent}}
{{/model}}
{{/models}}
{{/useAutoload}}
{{#useAutoload}}
{{#models}}
{{#model}}
{{moduleName}}.autoload :{{classname}}, '{{gemName}}/{{modelPackage}}/{{classFilename}}'
{{/model}}
{{/models}}
{{/useAutoload}}

# APIs
{{#apiInfo}}
{{#apis}}
{{^useAutoload}}
require '{{importPath}}'
{{/useAutoload}}
{{#useAutoload}}
{{moduleName}}.autoload :{{classname}}, '{{importPath}}'
{{/useAutoload}}
{{/apis}}
{{/apiInfo}}

module {{moduleName}}
  @config = Configuration.default
  SENTINEL = Object.new
  class << self

    private def is_sentinel(value)
      value == SENTINEL
    end

    def host
      @config.host
    end

    def host=(value)
      @config.host = value
    end
{{#apiKeyMethods}}
    # api key from OpenAPI spec
    def {{> securityKeyName}}
      @config.{{> securityKeyName}}
    end

    def {{> securityKeyName}}=(value)
      @config.{{> securityKeyName}} = value
    end
{{/apiKeyMethods}}
{{#clientState}}
    # client state from konfig.yaml
    def {{.}}
      @config.{{.}}
    end

    def {{.}}=(value)
      @config.{{.}} = value
    end
{{/clientState}}
{{#clientStateWithExamples}}
    # client state from konfig.yaml
    def {{name}}
      @config.{{name}}
    end

    def {{name}}=(value)
      @config.{{name}} = value
    end
{{/clientStateWithExamples}}

    # Customize default settings for the SDK using block.
    #   {{moduleName}}.configure do |config|
    #     config.host = "http://example.com"
    #   end
    # If no block given, return the default Configuration object.
    def configure
      if block_given?
        yield(Configuration.default)
      else
        Configuration.default
      end
    end
  end

  {{#apiInfo}}
  class Client
    {{#apis}}
    attr_reader :{{classNameSnakeCase}}
    {{/apis}}

    def initialize(config = Configuration.default)
      @api_client = ApiClient::new(config)
      {{#apis}}
      @{{classNameSnakeCase}} = {{moduleName}}::{{classname}}.new(@api_client)
      {{/apis}}
    end
  end
  {{/apiInfo}}
end
